//
//  HMRecommendTableViewController.m
//  subscribe
//
//  Created by 宋轩 on 17/1/1.
//  Copyright © 2017年 song. All rights reserved.
//

#import "HMRecommendTableViewController.h"
#import "HMRecommendTableViewCell.h"
#import "HMDetailsTableViewController.h"
#import "HMSubscribeViewModel.h"

@interface HMRecommendTableViewController ()

@property (nonatomic, strong) NSArray *subscribeModel;

@end

//标识符
static NSString *recommendID = @"RecommendID";

@implementation HMRecommendTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self loaddata];
    //注册
    [self.tableView registerNib:[UINib nibWithNibName:@"HMRecommendTableViewCell" bundle:nil] forCellReuseIdentifier:recommendID];
    
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 95, 0);
    
    [self.tableView addTableViewRefreshHeaderWhenPullToPerformAction:@selector(loaddata)];
}

- (void)loaddata
{
    [HMSubscribeViewModel getRecommendModelFinished:^(NSArray *arr) {
        _subscribeModel = arr;
//        NSLog(@"---------------%@", [NSThread currentThread]);
        [self.tableView reloadData];
        [self.tableView endRefresh];
    } Failed:^(NSError *error) {
        NSLog(@"%@----------------", error);
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

#pragma mark - Table view data source

//选择cell执行
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    HMDetailsTableViewController *vc = [[HMDetailsTableViewController alloc] init];
    
    vc.tid = [self.subscribeModel[indexPath.row] tid];
    //隐藏TabBar
    vc.hidesBottomBarWhenPushed = YES;
    //PUSH跳转
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

//数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.subscribeModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HMRecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:recommendID forIndexPath:indexPath];
    
    cell.recommendModel = self.subscribeModel[indexPath.row];
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 115;
}


@end
